@extends('admin.common.main')
@section('css')
<style>
</style>
@endsection
@section('cnt')
<div class="x-body">
    @include('admin.common.validate')
    @include('admin.common.msg')
    <form class="layui-form" action="{{ route('admin.role.update',$model) }}" method="post" id="form-member-add">
        {{ csrf_field() }}
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>账号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name"
                       autocomplete="off" class="layui-input" value="{{ $model->name }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" type="submit">
                添加用户
            </button>
        </div>
    </form>
</div>
@endsection
@section('js')
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script>
    $("#form-member-add").validate({
        //规则
        rules:{
            //表单元素名称
            name:{
                required:true
            }
        },
        messages:{
            username:"请输入角色名"
        },
        onkeyup:false,
        success:"valid",
        submitHandler:function (form) {
            //获取数据提交的地址
            //将form元素转化为jquery对象 使用 $("表单元素")
            var url = $(form).attr('action');
            var data = $(form).serialize();//_token=MJLZNt0QLAqHidErMkALtdymin4fIIOQALkeyZvT&name=1212
            //使用ajax提交
            $.ajax({
                url,
                data,
                type:'PUT'
            }).then(({status,msg}) => {
                if(status == 0){
                    layer.msg(msg,{icon:1,time:1000},function(){
                        var index=parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        window.parent.location.reload();
                    });
                }else{
                    layer.msg(msg);
                }
            });
            // $.post(url,data).then(({status,msg}) => {
            //     if(status == 0){
            //         layer.msg(msg,{icon:1,time:1000},function(){
            //             var index=parent.layer.getFrameIndex(window.name);
            //             parent.layer.close(index);
            //             window.parent.location.reload();
            //         })
            //     }else{
            //         layer.msg(msg);
            //     }
            // });
        }
    });


</script>
@endsection